﻿using System;
using System.IO;
using System.Net;
using TransferClientLib;
using TransferClientLib.UpLoad;
namespace TestClient
{
    class Program
    {
        private static string fileName = @"D:\Soft\AdbeRdr940_zh_CN.zip";
        //private static string fileName = @"D:\Soft\OPSystem\GhostXP_SP3.iso";新的分支
        private static void Main(string[] args)
        {
            EndPoint endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2020);
            UpLoadEngine engine = new UpLoadEngine();
            engine.Init(endpoint, fileName, Path.GetFileName(fileName));
            engine.TransferStep += new UpLoadEngine.TransferStepEventHandler(Program.socket_TransferStep);
            engine.TransferComplete += new UpLoadEngine.TransferCompleteEventHandler(Program.socket_TransferComplete);
            engine.FileExist += new UpLoadEngine.FileExistEventHandler(Program.socket_FileExist);
            engine.TransferError += new UpLoadEngine.TransferErrorEventHandler(Program.socket_TransferError);
            while (true)
            {
                if (Console.ReadLine() == "q")
                {
                    return;
                }
                engine.BeginUpLoad();
            }
        }

        private static bool socket_FileExist(EventArgs e)
        {
            Console.WriteLine("存在相同的文件，是否覆盖？");
            string str = Console.ReadLine();
            return (str == "y");
        }

        private static void socket_TransferComplete(EventArgs e)
        {
            Console.WriteLine("上传完成");
        }

        private static void socket_TransferError(TransferErrorEventArgs e)
        {
            Console.WriteLine(e.Exception.Message);
        }

        private static void socket_TransferStep(TransferStepEventArgs e)
        {
            Console.WriteLine(string.Format("已上传大小{0},本次上传{1},总计大小{2}", e.TransferLen, e.CurrentPacket, e.TotalLen));
        }
    }
}
